package org.syncsoft.overalt.gui.api.window;

import java.io.File;
import java.util.Collection;

import org.syncsoft.overalt.common.exception.SystemException;
import org.syncsoft.overalt.domain.community.entity.Community;
import org.syncsoft.overalt.domain.tag.entity.Tag;
import org.syncsoft.overalt.gui.api.WindowContextValue;

/**
 * 
 * @author tptfc
 *
 */
public abstract class AbstractSendFileWindowController<T extends AbstractSendFileWindow> extends AbstractWindowController<T> {
	private String filePath;
	
	public AbstractSendFileWindowController(String filePath) {
		setFilePath(filePath);
	}
	
	@Override
	protected WindowContextValue getUpdateWindowContextValue() throws SystemException {
		WindowContextValue context = new WindowContextValue();
		
		if (getFilePath() != null) {
			File file = new File(getFilePath());
			if (file.exists() && file.isFile()) {
				String folderPath = file.getParent();
				
				Collection<Tag> requiredTags = getUpdateRequiredTags(getFilePath());
				context.addMultiValue("requiredTags", requiredTags);
				
				context.addValue("requiredCommunity", getUpdateRequiredCommunities(getFilePath()));
				getWindow().update(context);
			}
		}
		
		return context;
	}
	
	protected abstract Collection<Tag> getUpdateRequiredTags(String filePath) throws SystemException;
	protected abstract Collection<Community> getUpdateRequiredCommunities(String filePath) throws SystemException;

	protected String getFilePath() {
		return filePath;
	}
	protected void setFilePath(String filePath) {
		this.filePath = filePath;
	}
}
